package com.campus.backend.controller;

import com.campus.backend.bean.feedback.FeedbackTypeBean;
import com.campus.backend.bean.feedback.FeedbackTypeQueryParam;
import com.campus.backend.service.FeedbackTypeService;
import com.campus.backend.vo.feedback.FeedbackTypeVo;
import com.campus.common.bean.common.Pagination;
import com.campus.common.bean.common.Resp;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 反馈类型配置表 前端控制器
 * </p>
 *
 * @author ZhaoYuJie
 * @since 2025-06-06
 */
@Api(tags = "反馈类型管理")
@RestController
@RequestMapping("/feedbackType")
public class FeedbackTypeController {

    @Autowired
    private FeedbackTypeService feedbackTypeService;

    /**
     * 分页查询反馈类型列表
     *
     * @param param 查询参数
     * @return 分页结果
     */
    @ApiOperation("分页查询反馈类型列表")
    @GetMapping("/page")
    public Resp<Pagination<FeedbackTypeVo>> page(@Validated FeedbackTypeQueryParam param) {
        PageInfo<FeedbackTypeVo> pageInfo = feedbackTypeService.getFeedbackTypeListPage(param);
        return Resp.successPageable(pageInfo);
    }

    /**
     * 获取反馈类型详情
     *
     * @param typeId 反馈类型ID
     * @return 反馈类型详情
     */
    @ApiOperation("获取反馈类型详情")
    @GetMapping("/{typeId}")
    public Resp<FeedbackTypeVo> detail(@PathVariable Integer typeId) {
        FeedbackTypeVo feedbackTypeVo = feedbackTypeService.getFeedbackTypeById(typeId);
        return Resp.success(feedbackTypeVo);
    }

    /**
     * 新增反馈类型
     *
     * @param typeBean 反馈类型信息
     * @return 新增结果
     */
    @ApiOperation("新增反馈类型")
    @PostMapping
    public Resp<Integer> create(@RequestBody @Validated FeedbackTypeBean typeBean) {
        Integer typeId = feedbackTypeService.addFeedbackType(typeBean);
        return Resp.success(typeId);
    }

    /**
     * 更新反馈类型
     *
     * @param typeBean 反馈类型信息
     * @return 更新结果
     */
    @ApiOperation("更新反馈类型")
    @PutMapping
    public Resp<String> update(@RequestBody @Validated FeedbackTypeBean typeBean) {
        feedbackTypeService.updateFeedbackType(typeBean);
        return Resp.success();
    }

    /**
     * 删除反馈类型
     *
     * @param typeId 反馈类型ID
     * @return 删除结果
     */
    @ApiOperation("删除反馈类型")
    @DeleteMapping("/{typeId}")
    public Resp<String> delete(@PathVariable Integer typeId) {
        feedbackTypeService.deleteFeedbackType(typeId);
        return Resp.success();
    }

    /**
     * 获取所有启用的反馈类型（用于下拉选择）
     *
     * @return 反馈类型列表
     */
    @ApiOperation("获取所有启用的反馈类型")
    @GetMapping("/enabled")
    public Resp<List<FeedbackTypeVo>> getAllEnabled() {
        List<FeedbackTypeVo> feedbackTypeList = feedbackTypeService.getAllEnabledFeedbackTypes();
        return Resp.success(feedbackTypeList);
    }
}
